package edu.cuit.avatar.array;

public class ArrayDemo {
    public static void main(String[] args) {
        /*
        动态初始化：只告知数组需要几个存储空间，但是并未决定要存哪些值，由系统为每个元素指定初始值
            数值型: 0
            boolean: false
            char: '\u0000'
            引用类型: null
         */
        float[] scores = new float[100];

        System.out.println(scores[0]); //通过索引(基于0)访问数组的元素 // 0

        scores[0] = 92.5f;
        System.out.println(scores[0]);

        //静态初始化
        //String[] chineseZodiac = new String[]{"monkey", "raster", "dog", "pig", "mouse", "ox", "tiger", "rabbit", "loong", "snake", "horse", "sheep"};
        String[] chineseZodiac = {"monkey", "raster", "dog", "pig", "mouse", "ox", "tiger", "rabbit", "loong", "snake", "horse", "sheep"};

        System.out.println("2025 is " + chineseZodiac[2025 % 12]);
        //可以使用length属性获取数组大小(元素个数)
        System.out.println(chineseZodiac.length); // 12
        //System.out.println(chineseZodiac); // toString()

        boolean[] results = new boolean[2];
        System.out.println(results[0]);//false
        System.out.println(results[1]);//false

        //NullPointerException
        //ArrayIndexOutOfBoundsException: 数组索引下标越界异常
        //System.out.println(results[2]);

        for(String e : chineseZodiac)
            System.out.println(e);
    }
}
